#include <QCoreApplication>
#include <vector>
#include <QDebug>
#include <cmath>
using namespace std;
struct Point3D
{
    double x;
    double y;
    double z;
};

bool sphereLeastFit(const std::vector<Point3D> &points,
                    double &center_x, double &center_y, double &center_z, double &radius);
					
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    double cx = 111, cy = 222, cz = 333, r = 123;

    std::vector<Point3D> s;
    for(int i = 0; i < 100; i++)
    {
        Point3D p;
        double theta = i / 100.0 * 3.14;
        double phi = 2 * (i-50.0) /100.0 * 3.14;
        p.x = r * cos(theta) * cos(phi) + cx;
        p.y = r * cos(theta) * sin(phi) + cy;
        p.z = r * sin(theta) + cz;
        s.push_back(p);
    }
    double xx, yy, zz, rr;
    sphereLeastFit(s, xx, yy, zz, rr);

    qDebug() << xx;
    qDebug() << yy;
    qDebug() << zz;
    qDebug() << rr;

    return a.exec();
}
					